package cn.chenchendemospringboot.order_demo.controller;

import cn.chenchendemospringboot.order_demo.entity.Order;
import cn.chenchendemospringboot.order_demo.service.OrderService;
import cn.chenchendemospringboot.order_demo.service.impl.OrderServiceImpl;
import cn.chenchendemospringboot.order_demo.service.impl.OrderServiceImpl2;
import cn.chenchendemospringboot.order_demo.utils.DateTimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderServiceImpl2 orderService;

    @PostMapping("/insert")
    public boolean createOrder(@RequestBody Order order) {
        // 设置具体的字段值
//        order.setCustomerId(1234);
//        order.setProductId(1234);
//        order.setQuantity(1234);
        order.setOrderDate(DateTimeUtils.formatDefault(new Date())); // 当前日期和时间
//        order.setStatus("NEW");

        // 调用Service层的saveOrder方法
         orderService.addOrder(order);
        return true;
    }
}
